﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZeroBug.EasyFlow.Core
{
    public class Tray : Matrix
    {
        public string Description { get; set; }
        public Point2d LeftUpCorner { get; set; }
        public Point2d RightUpCorner { get; set; }
        public Point2d RightDownCorner { get; set; }
        public int NozzleCount { get; set; }
        public double NozzleOffsetX { get; set; }
        public double NozzleOffsetY { get; set; }
        public Tray()
        {
            
        }
        public Tray(string description, int rowCount, int colCount)
            : base(rowCount, colCount)
        {
            this.Description = description;
            this.LeftUpCorner = new Point2d(0,0);
            this.RightUpCorner = new Point2d(0,0);
            this.RightDownCorner = new Point2d(0,0);
        }
        public Point2d GetPosition(int index, int nozzleIndex)
        {
            (int, int) rc = GetPoint(index);

            double offsetX = (RightUpCorner.X - LeftUpCorner.X) / (ColCount - 1);
            double offsetY = (RightDownCorner.Y - RightUpCorner.Y) / (RowCount - 1);
            double smallOffsetX = (RightDownCorner.X - RightUpCorner.X) / (RowCount - 1);
            double smallOffsetY = (RightUpCorner.Y - LeftUpCorner.Y) / (ColCount - 1);

            double x = LeftUpCorner.X + offsetX * rc.Item2 + smallOffsetX * rc.Item1;
            double y = LeftUpCorner.Y + offsetY * rc.Item1 + smallOffsetY * rc.Item2;

            return new Point2d(x, y);
        }

    }
}
